include<tools/util.scad>

$fn=100;

//motor_shelf();
//translate([-100,0,0])turn_plate_base();
//translate([0,140,0])plate();
moto_link();
//translate([140,0,0])support_wheel();
//translate([0,-100,0])wheel_shelf();
//translate([0,-150,0]) fastening();

module motor_shelf(){
    difference(){
        union(){
            //电机架
            difference(){
                cube([35,25,52]);
                translate([3,-1,5])cube([22,31,66]);
                translate([-1,4,23.8])cube([39,19,60]);
                //电机固定孔
                translate([30,29,26.55])rotate([90,0,0])cylinder(h=30,d=3);
                translate([30,29,44.05])rotate([90,0,0])cylinder(h=30,d=3);        
            }
            //调速器架
            translate([35,0,0])union(){
                    cube([13,25,5]);
                    translate([13,0,0])cube([34.5,34,5]);
        
                    translate([47.5,34,35])rotate([-90,90,0]) {
                    union(){
                        difference(){
                            cube([35,34.5,19]);
                            translate([1,1,2])cube([33,32.5,18]);
                            translate([12,0,2])cube([10,5,18]);
                            translate([7,31,2])cube([20,5,18]);
                            
                        }
                        translate([33,15,2])cube([1,3,10]);
                    }
                }
        }
    }
        //安装固定孔
        translate([15,13,-1])cylinder(h=7,d=5);
        translate([65,13,-1])cylinder(h=7,d=5);
    }
    //调速器盖子
    pos=[[1,10],[1,20],[32.6,10],[32.6,20]];
    translate([50,-50,0]){
        cube([35,34.5,1.5]);
        for(i=[0:3]){
            translate([pos[i][0],pos[i][1],1.5])cube([1.4,2,3]);
        }
    }
    //马达固定销
    //translate([-10,5,1.5])rotate([0,-90,0])cylinder(h=30,d=2.8);
    //translate([-10,25,1.5])rotate([0,-90,0])cylinder(h=30,d=2.8);
}

module turn_plate_base(){
    translate([0,0,4])difference(){
        union(){
            difference(){
                union(){
               translate([0,0,8])d_bearing(r=40,height=16,ball_r=7.4,ball_num=10);

               //抬高
              translate([0,0,-4])cylinder(h=4,d=39);
                }
                translate([0,0,-5])cylinder(h=21,d=18);
            }
           translate([0,0,16])cylinder(h=45.5,r=40);
        }
        translate([0,0,16])cylinder(h=45.6,r=35.1);
        //连接固定槽
        translate([-3.5,-45,45])cube([7,90,7]);
    }
    //固定销
    translate([60,-45,0])cube([6.6,90,6.6]);
    translate([-70,-25,0])d_fastening_pair(rod_len=40,rod_diam=17.6,cap_diam=24,cap_height=2,nut_height=5);
    
 /*   //底盘
 translate([-70,0,0]) difference(){
        union(){
            cylinder(h=4,d=40);
            translate([0,0,13])difference(){
                cube([13.6,13.6,18],center=true);
                cube([9.6,9.6,19],center=true);
                //cylinder(h=20,d=17.5);
                //cylinder(h=21,d=13.5);                       
            }
        }
        //固定孔
        translate([13,0,0])cylinder(h=5,d=5);
        translate([13,0,2])cylinder(h=2.1,d=10);
        translate([-13,0,0])cylinder(h=5,d=5);
        translate([-13,0,2])cylinder(h=2.1,d=10);
    }*/
}
module plate(){
    difference(){
        union(){
            cylinder(h=2,r=80);
            translate([0,0,2])cylinder(h=25,r=35);

        }
         translate([0,0,2])cylinder(h=25.5,r=31);
        translate([-3.5,-45,15.5])cube([7,90,7]);
    }
    
}
module moto_link(){
    difference(){
        cylinder(h=5,d=62);
        cylinder(h=5.5,d=58);
    }
    difference(){
        union(){
            translate([0,0,2.5])union(){
                cube([59,4,5],center=true);
                cube([4,59,5],center=true);
            }
            cylinder(h=27,d=14);
        }
        translate([0,0,24])intersection(){
            cube([5.6,3.9,6.1],center=true);
            translate([0,0,-3])cylinder(h=6.1,d=5.6);
        }
    }
    
}

module support_wheel(){
    difference(){
        d_bearing(r=32.5,height=16,ball_r=7.2,ball_num=7);
        cube([7,7,27],center=true);
    }
    
}

module wheel_shelf(){
    difference(){
       cube([75,22,45]);
        translate([0,2,5])cube([76,18,41]);
        translate([0,0,5])cube([17,23,41]);
        translate([59,0,5])cube([17,23,41]);
        translate([9,2,0])cube([57,18,6]);
        translate([34,22,31.5])rotate([90,0,0])cube([7,17,27]);
        //安装孔
        translate([4,11,0])cylinder(h=6,d=5);
        translate([71,11,0])cylinder(h=6,d=5);
    }
    translate([0,30,6.6]) rotate([0,90,0])cube([6.6,6.6,27]);
}

module fastening(){
    //固定件
    for(i=[0:15:45]){
        translate([i,0,0])d_fastening_pair(rod_len=30,rod_diam=4.6,cap_diam=9,cap_height=2);
    }
    
    //电机固定销
    translate([0,-35,0])d_fastening_pair(rod_len=34,rod_diam=2.6,cap_diam=10,cap_height=1,nut_height=4);
     translate([15,-35,0])d_fastening_pair(rod_len=34,rod_diam=2.6,cap_diam=10,cap_height=1,nut_height=4);

}